//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "GaussLaguerreIntegration.h"
using namespace Cephei::QL::Math::Integrals;
#include <gen/QL/Math/Integrals/GaussianOrthogonalPolynomial.h>
#include <gen/QL/Math/Integrals/GaussianQuadrature.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Integrals::CGaussLaguerreIntegration::CGaussLaguerreIntegration (UInt64 n, Microsoft::FSharp::Core::FSharpOption<Double>^ s) : CGaussianQuadrature(CGaussLaguerreIntegration::typeid)
{
    try
    {
#ifdef HANDLE
        _phGaussLaguerreIntegration = NULL;
#endif
        QuantLib::Size _n = (QuantLib::Size)ValueHelper::Convert (n);
        QuantLib::Real _s = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (s) ? (QuantLib::Real)ValueHelper::Convert (s->Value) : 0.0); //4
        _ppGaussLaguerreIntegration = new boost::shared_ptr<QuantLib::GaussLaguerreIntegration> (new QuantLib::GaussLaguerreIntegration ( _n,  _s ));
        SetGaussianQuadrature (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussLaguerreIntegration));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Integrals::CGaussLaguerreIntegration::CGaussLaguerreIntegration (boost::shared_ptr<QuantLib::GaussLaguerreIntegration>& childNative, Object^ owner) : CGaussianQuadrature(CGaussLaguerreIntegration::typeid)
{
#ifdef HANDLE
	_phGaussLaguerreIntegration = NULL;
#endif
	_ppGaussLaguerreIntegration = &childNative;
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussLaguerreIntegration));
}
Cephei::QL::Math::Integrals::CGaussLaguerreIntegration::CGaussLaguerreIntegration (QuantLib::GaussLaguerreIntegration& childNative, Object^ owner) : CGaussianQuadrature(CGaussLaguerreIntegration::typeid)
{
#ifdef HANDLE
	_phGaussLaguerreIntegration = NULL;
#endif
	_ppGaussLaguerreIntegration = new boost::shared_ptr<QuantLib::GaussLaguerreIntegration> (&childNative);
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussLaguerreIntegration));
    _GaussLaguerreIntegrationOwner = owner;
    _GaussianQuadratureOwner = owner;
}

Cephei::QL::Math::Integrals::CGaussLaguerreIntegration::CGaussLaguerreIntegration (CGaussLaguerreIntegration^ copy) : CGaussianQuadrature(CGaussLaguerreIntegration::typeid)
{
#ifdef HANDLE
	_phGaussLaguerreIntegration = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppGaussLaguerreIntegration = new boost::shared_ptr<QuantLib::GaussLaguerreIntegration> (copy->GetShared());
        _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussLaguerreIntegration));
    }
}
Cephei::QL::Math::Integrals::CGaussLaguerreIntegration::CGaussLaguerreIntegration (System::Type^ t) : CGaussianQuadrature(CGaussLaguerreIntegration::typeid)
{
#ifdef HANDLE
	_phGaussLaguerreIntegration = NULL;
#endif
	if (!t->IsSubclassOf(CGaussLaguerreIntegration::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Integrals::CGaussLaguerreIntegration::CGaussLaguerreIntegration (QuantLib::Handle<QuantLib::GaussLaguerreIntegration>& childNative, Object^ owner)  : CGaussianQuadrature(CGaussLaguerreIntegration::typeid)
{
	_phGaussLaguerreIntegration = &childNative;
	_ppGaussLaguerreIntegration = &static_cast<boost::shared_ptr<QuantLib::GaussLaguerreIntegration>>(childNative.currentLink());
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussLaguerreIntegration));
    _GaussLaguerreIntegrationOwner = owner;
}
Cephei::QL::Math::Integrals::CGaussLaguerreIntegration::CGaussLaguerreIntegration (QuantLib::Handle<QuantLib::GaussLaguerreIntegration> childNative)  : CGaussianQuadrature(CGaussLaguerreIntegration::typeid)
{
	_phGaussLaguerreIntegration = &childNative;
	_ppGaussLaguerreIntegration = &static_cast<boost::shared_ptr<QuantLib::GaussLaguerreIntegration>>(childNative.currentLink());
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussLaguerreIntegration));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Integrals::CGaussLaguerreIntegration::CGaussLaguerreIntegration (QuantLib::GaussLaguerreIntegration childNative)  : CGaussianQuadrature(CGaussLaguerreIntegration::typeid)
{
#ifdef HANDLE
	_phGaussLaguerreIntegration = NULL;
#endif
	_ppGaussLaguerreIntegration = new boost::shared_ptr<QuantLib::GaussLaguerreIntegration> (new QuantLib::GaussLaguerreIntegration (childNative));
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussLaguerreIntegration));
}
#endif

Cephei::QL::Math::Integrals::CGaussLaguerreIntegration::~CGaussLaguerreIntegration ()
{
    if (_ppGaussLaguerreIntegration != NULL)
    {
	    delete _ppGaussLaguerreIntegration;
        _ppGaussLaguerreIntegration = NULL;
    }
}
Cephei::QL::Math::Integrals::CGaussLaguerreIntegration::!CGaussLaguerreIntegration ()
{
    if (_ppGaussLaguerreIntegration != NULL)
    {
	    delete _ppGaussLaguerreIntegration;
    }
}
QuantLib::GaussLaguerreIntegration& Cephei::QL::Math::Integrals::CGaussLaguerreIntegration::GetReference ()
{
    if (_ppGaussLaguerreIntegration == NULL) throw gcnew NativeNullException ();
	return **_ppGaussLaguerreIntegration;
}
boost::shared_ptr<QuantLib::GaussLaguerreIntegration>& Cephei::QL::Math::Integrals::CGaussLaguerreIntegration::GetShared ()
{
    if (_ppGaussLaguerreIntegration == NULL) throw gcnew NativeNullException ();
	return *_ppGaussLaguerreIntegration;
}
QuantLib::GaussLaguerreIntegration* Cephei::QL::Math::Integrals::CGaussLaguerreIntegration::GetPointer ()
{
    if (_ppGaussLaguerreIntegration == NULL) throw gcnew NativeNullException ();
	return &**_ppGaussLaguerreIntegration;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::GaussLaguerreIntegration>& Cephei::QL::Math::Integrals::CGaussLaguerreIntegration::GetHandle ()
{
	if (_phGaussLaguerreIntegration == NULL)
	{
		_phGaussLaguerreIntegration = new Handle<QuantLib::GaussLaguerreIntegration> (*_ppGaussLaguerreIntegration);
	}
	return *_phGaussLaguerreIntegration;
}
#endif
bool Cephei::QL::Math::Integrals::CGaussLaguerreIntegration::HasNative () 
{
	return (_ppGaussLaguerreIntegration != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Integrals::IGaussLaguerreIntegration^ Cephei::QL::Math::Integrals::CGaussLaguerreIntegration_Factory::Create (UInt64 n, Microsoft::FSharp::Core::FSharpOption<Double>^ s)
{
    return gcnew CGaussLaguerreIntegration ( n,  s);
}
